/**
 * 
 */
package beanstao.util.office.excel;

import org.dom4j.Element;

import beanstao.util.reflect.Mirror;
import beanstao.util.setting.Setting;

/**
 * @author beanstao@google.com 
 * 
 */
public class ExcelSetting extends Setting<Element>
{
	public IExcelFilePath excelFilePath()
	{
		return excelFilePath;
	}

	private IExcelFilePath excelFilePath = null;

	@Override
	protected void fillSettingData(Element element)
	{
		String pathClass = ((Element) element.selectSingleNode("ExcelFilePath")).attributeValue("class");
		Class<?> klass = null;
		try
		{
			klass = Class.forName(pathClass);
		}
		catch (ClassNotFoundException e)
		{
			this.logDebug(pathClass + "未找到。");
		}
		Mirror<?> mirror = Mirror.me(klass);
		Object excelFilePath = null;
		try
		{
			excelFilePath = mirror.born();
		}
		catch (Exception e)
		{
			this.logDebug(excelFilePath + "未初始化。");
		}
		this.excelFilePath = (IExcelFilePath) excelFilePath;
	}

	/**
	 * @return 返回本类型的单建实例(延迟加载,并对多线程进行处理)
	 */
	public static ExcelSetting ME()
	{
		return Single.instance;
	}

	/**
	 * 为单建模式设计的内部静态类型
	 */
	static class Single
	{
		/**
		 * 多线程锁
		 */
		static Object lock = new Object();
		static
		{
			synchronized (lock)
			{
				instance = new ExcelSetting();
			}
		}
		static ExcelSetting instance;
	}

	/**
	 * 针对单建模式,私有化本类型构造函数
	 */
	private ExcelSetting()
	{
	}

}
